package cn.com.jenson.common;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;

import java.util.Objects;

/**
 * BasicSearchBo<br>
 * SearchBo公共类
 */
@Getter
@Setter
public abstract class BasicSearchBo {
    private Integer page = 0;
    private Integer limit = 50;

    public PageRequest getPageRequest() {
        Sort sort = getPageSort();
        if (Objects.nonNull(sort)) {
            return getPageRequest(sort);
        }
        return PageRequest.of(Math.max(0, this.getPage() - 1), getLimit());
    }

    public PageRequest getPageRequest(Sort sort) {
        if (Objects.nonNull(sort)) {
            return PageRequest.of(Math.max(0, this.getPage() - 1), getLimit(), sort);
        }
        return PageRequest.of(Math.max(0, this.getPage() - 1), getLimit());
    }

    public Sort getPageSort() {
        return null;
    }
}
